package cn.xscrum.system.service.impl;

import java.util.List;
import java.util.ArrayList;
import cn.xscrum.common.core.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.xscrum.system.mapper.SysAreasMapper;
import cn.xscrum.system.domain.SysAreas;
import cn.xscrum.system.service.ISysAreasService;
import cn.xscrum.common.core.text.Convert;

/**
 * 区域信息Service业务层处理
 * 
 * @author xscrum
 * @date 2020-01-05
 */
@Service
public class SysAreasServiceImpl implements ISysAreasService 
{
    @Autowired
    private SysAreasMapper sysAreasMapper;

    /**
	 * 查询区域信息
     * 
     * @param areaId 区域信息ID
     * @return 区域信息
     */
    @Override
    public SysAreas selectSysAreasById(Long areaId)
    {
        return sysAreasMapper.selectSysAreasById(areaId);
    }

    /**
	 * 查询区域信息列表
     * 
     * @param sysAreas 区域信息
     * @return 区域信息
     */
    @Override
    public List<SysAreas> selectSysAreasList(SysAreas sysAreas)
    {
        return sysAreasMapper.selectSysAreasList(sysAreas);
    }

    /**
	 * 新增区域信息
     * 
     * @param sysAreas 区域信息
     * @return 结果
     */
    @Override
    public int insertSysAreas(SysAreas sysAreas)
    {
        return sysAreasMapper.insertSysAreas(sysAreas);
    }

    /**
	 * 修改区域信息
     * 
     * @param sysAreas 区域信息
     * @return 结果
     */
    @Override
    public int updateSysAreas(SysAreas sysAreas)
    {
        return sysAreasMapper.updateSysAreas(sysAreas);
    }

    /**
	 * 删除区域信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSysAreasByIds(String ids)
    {
        return sysAreasMapper.deleteSysAreasByIds(Convert.toStrArray(ids));
    }

    /**
	 * 删除区域信息信息
     * 
     * @param areaId 区域信息ID
     * @return 结果
     */
    @Override
    public int deleteSysAreasById(Long areaId)
    {
        return sysAreasMapper.deleteSysAreasById(areaId);
    }

    /**
	 * 查询区域信息树列表
     * 
     * @return 所有区域信息信息
     */
    @Override
    public List<Ztree> selectSysAreasTree()
    {
        List<SysAreas> sysAreasList = sysAreasMapper.selectSysAreasList(new SysAreas());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (SysAreas sysAreas : sysAreasList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(sysAreas.getAreaId());
            ztree.setpId(sysAreas.getParentId());
            ztree.setName(sysAreas.getAreaName());
            ztree.setTitle(sysAreas.getAreaName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}